package com.xwt.web.service;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import com.xwt.web.dao.AuthorityRepository;
import com.xwt.web.dao.UserRepository;
import com.xwt.web.entity.Authority;
import com.xwt.web.entity.User;
/**
 * 自定义UserDetailsService,用于UsernamePasswordFilter用户名密码验证
 * @author Administrator
 *
 */
@Service
public class SecurityUserDetailService implements UserDetailsService{
	private Logger logger = LoggerFactory.getLogger(getClass());

	@Autowired	
	private UserRepository userDao;
	@Autowired
	private AuthorityRepository authorityDao;
	
	@Override
	public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
		logger.info("SecurityUserDetailService:"+username);
		User user=userDao.findByUsername(username);
		List<Authority> list=authorityDao.findByUsername(username);
		user.setList(list);
		return user;
	}

}
